'use strict';
const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER, TEXT,DECIMAL } = app.Sequelize;
  const Express = app.model.define(
      'express',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          order_id: INTEGER(11),
          address_id: INTEGER(11),
          member_id: INTEGER(11),
          code: STRING(255),
          name: STRING(255),
          create_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          },
          updated_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          }
      },
      {
          tableName: 'express',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    // OrderGoods.associate = function () {
    //     OrderGoods.hasMany(app.model.OrderGoods, { foreignKey: 'order_id', targetKey: 'id'})
    //     OrderGoods.hasMany(app.model.Address, { foreignKey: 'address_id', targetKey: 'id'})
    // }
    return Express
};
